package cn.ekuma.epos.datalogic.define.dao.crm.service;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.crm.service.I_Telephone;

import com.openbravo.bean.AppUser;
import com.openbravo.bean.Customer;
import com.openbravo.bean.crm.service.Telephone;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class TelephoneDAO extends ModifiedLogDAO<Telephone>{

    public TelephoneDAO(I_Session s) {
        super(s);
    }

     @Override
    public TableDefinition getTable() {
        return new TableDefinition(s,
                "TELEPHONE",
                new Field[]{
                   new Field(I_Telephone.ID,Datas.STRING, Formats.STRING),
                   new Field(I_Telephone.CALLTIME,Datas.TIMESTAMP, Formats.TIMESTAMP),
                   new Field(I_Telephone.SUBJECT,Datas.STRING, Formats.STRING),
                   new Field(I_Telephone.USERID,Datas.STRING, Formats.STRING,AppUser.class),
                   new Field(I_Telephone.PRIORITY,Datas.STRING, Formats.STRING),
                   new Field(I_Telephone.STATE,Datas.STRING, Formats.STRING),
                   new Field(I_Telephone.NEXTTIME,Datas.TIMESTAMP, Formats.TIMESTAMP),
                   new Field(I_Telephone.RELATIONID,Datas.STRING, Formats.STRING),
                   new Field(I_Telephone.RELATIONMAN,Datas.STRING, Formats.STRING),
                   new Field(I_Telephone.ENDTIME,Datas.TIMESTAMP, Formats.TIMESTAMP),
                   new Field(I_Telephone.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP),
                   new Field(I_Telephone.USERMAN,Datas.STRING, Formats.STRING),
                   new Field(I_Telephone.SUBJECTDESC,Datas.STRING, Formats.STRING),
                   new Field(I_Telephone.MODE,Datas.STRING, Formats.STRING),
                   new Field(I_Telephone.CUSTOMERID,Datas.STRING, Formats.STRING,Customer.class)
                } ,
                new int[]{0});
    }

	@Override
	public void writeInsertValues(DataWrite dp, Telephone obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setTimestamp(2,obj.getCallTime());
		dp.setString(3,obj.getSubject());
		dp.setString(4,obj.getUserId());
		dp.setInt(5,obj.getPriority());
		dp.setString(6,obj.getState());
		dp.setTimestamp(7,obj.getNextTime());
		dp.setString(8,obj.getRelationID());
		dp.setString(9,obj.getRelationMan());
		dp.setTimestamp(10,obj.getEndTime());
		dp.setTimestamp(11,obj.getLastModified());
		dp.setString(12,obj.getUserMan());
		dp.setString(13,obj.getSubjectDesc());
		dp.setString(14,obj.getMode());
		dp.setString(15,obj.getCustomerId());
	}

	@Override
	public Class getSuportClass() {
		return Telephone.class;
	}

	@Override
	public Telephone readValues(DataRead dr, Telephone obj)
			throws BasicException {
		if(obj==null)
			obj=new Telephone();
		obj.setKey(dr.getString(1));
		obj.setCallTime(dr.getTimestamp(2));
		obj.setSubject(dr.getString(3));
		obj.setUserId(dr.getString(4));
		obj.setPriority(dr.getInt(5));
		obj.setState(dr.getString(6));
		obj.setNextTime(dr.getTimestamp(7));
		obj.setRelationID(dr.getString(8));
		obj.setRelationMan(dr.getString(9));
		obj.setEndTime(dr.getTimestamp(10));
		obj.setLastModified(dr.getTimestamp(11));
		obj.setUserMan(dr.getString(12));
		obj.setSubjectDesc(dr.getString(13));
		obj.setMode(dr.getString(14));
		obj.setCustomerId(dr.getString(15));
		return obj;
	}
}
